"""
验证用户profile是否创建成功
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from dotenv import load_dotenv
load_dotenv()

from app import create_app
from app.models.user import User


def verify_profile():
    """验证profile"""
    app = create_app('development')
    
    with app.app_context():
        print("=" * 60)
        print("验证用户 S20251011 的 profile")
        print("=" * 60)
        
        user = User.query.filter_by(username='S20251011').first()
        
        if user:
            print(f"\n✅ 用户信息：")
            print(f"ID: {user.id}")
            print(f"用户名: {user.username}")
            print(f"姓名: {user.last_name}{user.first_name}")
            print(f"角色: {user.role}")
            print(f"学院: {user.college}")
            print(f"系部: {user.department}")
            
            if user.student_profile:
                print(f"\n✅ StudentProfile 存在：")
                print(f"Profile ID: {user.student_profile.id}")
                print(f"Student ID: {user.student_profile.student_id}")
                print(f"Major: {user.student_profile.major}")
                print(f"Grade Level: {user.student_profile.grade_level}")
                print(f"\n🎉 现在可以为该学生添加课程了！")
            else:
                print(f"\n❌ StudentProfile 不存在")
        else:
            print("\n❌ 用户未找到")
        
        print("\n" + "=" * 60)
        print("统计信息")
        print("=" * 60)
        
        from app.models.user import StudentProfile, TeacherProfile
        
        total_students = User.query.filter_by(role='student').count()
        students_with_profile = User.query.filter_by(role='student').join(StudentProfile).count()
        
        total_teachers = User.query.filter_by(role='teacher').count()
        teachers_with_profile = User.query.filter_by(role='teacher').join(TeacherProfile).count()
        
        print(f"学生总数: {total_students}")
        print(f"有 profile 的学生: {students_with_profile}")
        print(f"缺少 profile 的学生: {total_students - students_with_profile}")
        print(f"\n教师总数: {total_teachers}")
        print(f"有 profile 的教师: {teachers_with_profile}")
        print(f"缺少 profile 的教师: {total_teachers - teachers_with_profile}")
        print("=" * 60)


if __name__ == '__main__':
    verify_profile()


